﻿// JavaScript Document
(function($) {

    ///Menu Builder
    jQuery.fn.twSimpleMenu = function(settings) {
        var defaults = { dataURL: "twTabHead.txt", target: "#ContentsHolder", titleLoad: "Loading list..", messageLoad: "Please wait few second...", munuIndex: 0 }

        var options = jQuery.extend(defaults, settings);
        var holder = $(this);

        $.getJSON(options.dataURL, function(data) {
            $(data).each(function(i) {
                $(holder).append('<div class="topMenuItem" link="' + data[i].link + '">' + data[i].caption + '</div>');
            });

            topMenuItem(holder, options.target, options.titleLoad, options.messageLoad, options.munuIndex);
        });

    }

    function topMenuItem(menuHolder, target, titleLoad, messageLoad, munuIndex) {
        $(menuHolder).find("div.topMenuItem").css({ "cursor": "pointer" }).addClass("ui-state-default ui-corner-top")
		.click(function() {
		    $(this).addClass("ui-state-active")
			.siblings().removeClass("ui-state-active");
		    var isUrl = $(this).attr("link");
		    if (isUrl != "") {
				//fix ---del validate div
				$(".formErrorContent").parent().remove();
				//
				//$(target).load(isUrl);
				window.location.href = window.location.protocol + "//" + window.location.host + "/" + isUrl;
		    }
		});
		$(menuHolder).find("div.topMenuItem:eq(" + munuIndex + ")").addClass("ui-state-active")
        //$(menuHolder).find("div.topMenuItem:eq(" + munuIndex + ")").click();
    }



})(jQuery);

/*function MenuUnblock(){
	$("body").unblock();
}*/